class_name EquipmentPoisonPot
extends EquipmentBase


@onready var hit_area: Area2D = $HitArea
var poison_interval: float = 1.0
var poison_timer: float = 0


func _ready() -> void:
	poison_timer = poison_interval


func _physics_process(delta: float) -> void:
	poison_timer -= delta
	if poison_timer <= 0:
		poison_timer = poison_interval
		process_poison()
	

func process_poison():
	var areas = hit_area.get_overlapping_areas()
	if areas.size() <= 0: return
	
	for area in areas:
		var source = area.source
		if not source is UnitBase: return
		
		var poison_hit_rate = item_data.item_config.poison_hit_rate 
		var is_hit = randf() < poison_hit_rate
		if is_hit and not source.get_buff_by_name("buff_poison"):
			var buff_inst = source.add_buff("buff_poison", holder)
			
			buff_inst.duration = item_data.item_config.poison_debuff_duration
			buff_inst.damage_per_second = item_data.item_config.poison_damage_per_second
			buff_inst.start_buff()
	
	
